/**
 * Description:
 * Class Name:MatchesTest
 * Date:2022/2/22 10:55
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第7章_Java基础类库._7_5_正则表达式._7_5_2_创建正则表达式;

import java.util.regex.*;

public class MatchesTest {
    public static void main(String[] args) {
        String[] mails = {
          "kongyeeku@163.com",
          "kongyeeku@gmail.com",
          "ligang@crazyit.org",
          "wawa@abc.xx",
        };
        var mailRegEx = "\\w{3,20}@\\w+\\.(com|org|cn|net|gov)";
        var mailPattern = Pattern.compile(mailRegEx);
        Matcher matcher = null;
        for (var mail :
                mails) {
            if (matcher == null) {
                matcher = mailPattern.matcher(mail);
            }
            else {
                matcher.reset(mail);
            }
//            matcher = mailPattern.matcher(mail);        // ①——>其实把上面的if-else注释掉，采用这一句就可完成
            String result = mail + (matcher.matches() ? "是" : "不是") + "一个有效的邮箱地址！";
            System.out.println(result);
        }
    }
}
